{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>已采</th>\n",
       "      <th>已发</th>\n",
       "      <th>电商平台</th>\n",
       "      <th>品牌</th>\n",
       "      <th>评论</th>\n",
       "      <th>时间</th>\n",
       "      <th>型号</th>\n",
       "      <th>PageUrl</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>京东</td>\n",
       "      <td>AO</td>\n",
       "      <td>挺好的 ，安装人员很负责 指的夸奖</td>\n",
       "      <td>2014/8/26 9:07</td>\n",
       "      <td>AO史密斯（A.O.Smith） ET300J-60 电热水器 60升</td>\n",
       "      <td>http://s.club.jd.com/productpage/p-1008025-s-0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>京东</td>\n",
       "      <td>AO</td>\n",
       "      <td>自己安装的，感觉蛮好。后续追加。</td>\n",
       "      <td>2014/10/17 14:24</td>\n",
       "      <td>AO史密斯（A.O.Smith） ET300J-60 电热水器 60升</td>\n",
       "      <td>http://s.club.jd.com/productpage/p-1008025-s-0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>京东</td>\n",
       "      <td>AO</td>\n",
       "      <td>\\n\\nAO史密斯（A.O.Smith） ET300J-60 电热水器 60升 还没安装</td>\n",
       "      <td>2014/11/12 13:36</td>\n",
       "      <td>AO史密斯（A.O.Smith） ET300J-60 电热水器 60升</td>\n",
       "      <td>http://s.club.jd.com/productpage/p-1008025-s-0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>京东</td>\n",
       "      <td>AO</td>\n",
       "      <td>还没装，等安装之后再来吧，为装修备的货。</td>\n",
       "      <td>2014/11/16 0:04</td>\n",
       "      <td>AO史密斯（A.O.Smith） ET300J-60 电热水器 60升</td>\n",
       "      <td>http://s.club.jd.com/productpage/p-1008025-s-0...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>京东</td>\n",
       "      <td>AO</td>\n",
       "      <td>大小刚刚好，安装收了140材料费，活接、弯头啥的。试机顺利，16度加热到30度用了6分钟左右...</td>\n",
       "      <td>2014/11/11 8:11</td>\n",
       "      <td>AO史密斯（A.O.Smith） ET300J-60 电热水器 60升</td>\n",
       "      <td>http://s.club.jd.com/productpage/p-1008025-s-0...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Id    已采     已发 电商平台  品牌  \\\n",
       "0   1  True  False   京东  AO   \n",
       "1   2  True  False   京东  AO   \n",
       "2   3  True  False   京东  AO   \n",
       "3   4  True  False   京东  AO   \n",
       "4   5  True  False   京东  AO   \n",
       "\n",
       "                                                  评论                时间  \\\n",
       "0                                  挺好的 ，安装人员很负责 指的夸奖    2014/8/26 9:07   \n",
       "1                                   自己安装的，感觉蛮好。后续追加。  2014/10/17 14:24   \n",
       "2       \\n\\nAO史密斯（A.O.Smith） ET300J-60 电热水器 60升 还没安装  2014/11/12 13:36   \n",
       "3                               还没装，等安装之后再来吧，为装修备的货。   2014/11/16 0:04   \n",
       "4  大小刚刚好，安装收了140材料费，活接、弯头啥的。试机顺利，16度加热到30度用了6分钟左右...   2014/11/11 8:11   \n",
       "\n",
       "                                    型号  \\\n",
       "0  AO史密斯（A.O.Smith） ET300J-60 电热水器 60升   \n",
       "1  AO史密斯（A.O.Smith） ET300J-60 电热水器 60升   \n",
       "2  AO史密斯（A.O.Smith） ET300J-60 电热水器 60升   \n",
       "3  AO史密斯（A.O.Smith） ET300J-60 电热水器 60升   \n",
       "4  AO史密斯（A.O.Smith） ET300J-60 电热水器 60升   \n",
       "\n",
       "                                             PageUrl  \n",
       "0  http://s.club.jd.com/productpage/p-1008025-s-0...  \n",
       "1  http://s.club.jd.com/productpage/p-1008025-s-0...  \n",
       "2  http://s.club.jd.com/productpage/p-1008025-s-0...  \n",
       "3  http://s.club.jd.com/productpage/p-1008025-s-0...  \n",
       "4  http://s.club.jd.com/productpage/p-1008025-s-0...  "
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# -*- coding:utf-8 -*-\n",
    "import pandas as pd\n",
    "inputfile = 'huizong.csv' # 评论汇总文件\n",
    "data = pd.read_csv(inputfile, encoding = 'utf-8')\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 55774 entries, 95898 to 151671\n",
      "Data columns (total 1 columns):\n",
      "评论    55400 non-null object\n",
      "dtypes: object(1)\n",
      "memory usage: 871.5+ KB\n"
     ]
    }
   ],
   "source": [
    "result = data[[u'评论']][data[u'品牌'] == u'美的']\n",
    "result.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>评论</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>95898</th>\n",
       "      <td>京东商城信得过，买的放心，用的省心、安心、放心！</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95899</th>\n",
       "      <td>给公司宿舍买的，上门安装很快，快递也送的及时，不错的。给五分吧</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95900</th>\n",
       "      <td>美的值得信赖，质量不错</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95901</th>\n",
       "      <td>不错不错的哦，第一次在京东买这些产品，感觉相当好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95902</th>\n",
       "      <td>很满意，水方一晚上都还是热的早上还能再洗，</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    评论\n",
       "95898         京东商城信得过，买的放心，用的省心、安心、放心！\n",
       "95899  给公司宿舍买的，上门安装很快，快递也送的及时，不错的。给五分吧\n",
       "95900                      美的值得信赖，质量不错\n",
       "95901         不错不错的哦，第一次在京东买这些产品，感觉相当好\n",
       "95902            很满意，水方一晚上都还是热的早上还能再洗，"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 必须导入下面这个包，要不然会报错'ascii' codec can't encode characters in position\n",
    "# Python在安装时，默认的编码是ascii，当程序中出现非ascii编码时，python的处理常常会报这样的错\n",
    "import sys\n",
    "reload(sys)\n",
    "sys.setdefaultencoding( \"utf-8\" )\n",
    "result.to_csv('1_1my_meidi_jd.txt', index = False, header = False) # 将评论提取后保存到txt中，不要索引，不要列名（***）\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
